package health_system.health_system.websocket.Test;

import health_system.health_system.websocket.Model.CommunicationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一通信控制器
 * 提供WebRTC和WebSocket配置信息
 */
@RestController
@RequestMapping("/api/communication")
public class MediaCommunicationServerController {

    private final MediaCommunicationServerConfig config;

    @Autowired
    public MediaCommunicationServerController(MediaCommunicationServerConfig config) {
        this.config = config;
    }

    /**
     * 获取WebRTC配置
     * @return WebRTC配置信息
     */
    @GetMapping("/webrtc-config")
    public ResponseEntity<Map<String, Object>> getWebRTCConfig() {
        Map<String, Object> configMap = new HashMap<>();
        configMap.put("iceServers", config.getIceServersJson());
        configMap.put("maxBitrate", config.getMaxBitrate());
        configMap.put("videoCodec", config.getVideoCodec());
        configMap.put("audioCodec", config.getAudioCodec());
        return ResponseEntity.ok(configMap);
    }

    /**
     * 获取WebSocket端点信息
     * @return WebSocket端点信息
     */
    @GetMapping("/websocket-info")
    public ResponseEntity<Map<String, String>> getWebSocketInfo() {
        Map<String, String> infoMap = new HashMap<>();
        infoMap.put("endpoint", config.getWebsocketEndpoint());
        infoMap.put("supportedModes", String.join(",", 
            CommunicationUtils.CommunicationMode.VIDEO.getValue(),
            CommunicationUtils.CommunicationMode.AUDIO.getValue(),
            CommunicationUtils.CommunicationMode.SCREEN.getValue()
        ));
        return ResponseEntity.ok(infoMap);
    }

    /**
     * 获取通信模式信息
     * @return 通信模式信息
     */
    @GetMapping("/modes")
    public ResponseEntity<Map<String, String>> getCommunicationModes() {
        Map<String, String> modesMap = new HashMap<>();
        modesMap.put("video", CommunicationUtils.CommunicationMode.VIDEO.getValue());
        modesMap.put("audio", CommunicationUtils.CommunicationMode.AUDIO.getValue());
        modesMap.put("screen", CommunicationUtils.CommunicationMode.SCREEN.getValue());
        return ResponseEntity.ok(modesMap);
    }

    /**
     * 健康检查端点
     * @return 健康状态
     */
    @GetMapping("/health")
    public ResponseEntity<Map<String, String>> healthCheck() {
        Map<String, String> healthMap = new HashMap<>();
        healthMap.put("status", "UP");
        healthMap.put("service", "UnifiedCommunication");
        return ResponseEntity.ok(healthMap);
    }
} 